import { Controller,Headers, Get, Post, Body, Put,Query, Param, Delete } from '@nestjs/common';
import { InformationService } from './information.service';
import {  ApiTags } from '@nestjs/swagger';
import {InformationDto} from './dto/information.dto'
import { isNoAuth } from 'src/utils/decorator/jwt.decorator';
@ApiTags('情报管理')
@Controller('information')
@isNoAuth()
export class InformationController {
  constructor(private readonly informationService: InformationService) {}

  @Post("add")
  create(@Headers() header,@Body() informationDto: InformationDto) {
    const dto = {...informationDto, userId: header.userid, time: (new Date().getTime()).toString() }
    return this.informationService.create(dto);
  }

  @Get("list")
  list(@Headers() header,@Query() query):Promise<any> {
    return this.informationService.list(query.page,query.pageSize,header.userid);
  }

  @Get("search")
  async search(@Headers() header,@Query() query):Promise<InformationDto[]> {
    return  await this.informationService.search(query.keyword, query.targ, header.userid);
  }
  @Put('update/:id')
  update(@Param() param, @Body() informationDto: InformationDto) {
    return this.informationService.update(param.id, informationDto);
  }

  @Delete('del')
  remove(@Query() query):Promise<string> {
    return this.informationService.remove(query.id);
  }
}
